package com.niiwoo.civet.user.service.duboo;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.user.dto.UserAndContentDTO;
import com.niiwoo.civet.user.dto.UserAndParamsDTO;
import com.niiwoo.civet.user.service.SendSmsDubboService;
import com.niiwoo.civet.user.service.local.SendSmsLocalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.List;

@Slf4j
@Service(version = "1.0.0")
public class SendSmsDubboServiceImpl implements SendSmsDubboService {

    @Autowired
    private SendSmsLocalService sendSmsLocalService;

    @Value(value = "${smsService.enable:false}")
    private Boolean enable;

    private boolean isEnableSMS() {
        return enable;
    }

    @Override
    public void sendSms(List<UserAndParamsDTO> userAndParamsList, String templateKey, Date date) {
        if (!isEnableSMS()) {
            log.info("短信发送被禁用");
            return;
        }
        Assert.notEmpty(userAndParamsList,"userAndParamsList 为空");
        Assert.notNull(templateKey,"templateKey 为空");
        sendSmsLocalService.sendSms(userAndParamsList,templateKey,date);
    }

    @Override
    public void sendSms(List<UserAndContentDTO> userAndContentList, Date date) {
        if (!isEnableSMS()) {
            log.info("短信发送被禁用");
            return;
        }
        Assert.notEmpty(userAndContentList,"userAndContentList 为空");
        sendSmsLocalService.sendSms(userAndContentList,date);
    }


    @Override
    public void sendSmsByUserId(String userId, String templateKey, List<Object> params) {
        if (!isEnableSMS()) {
            log.info("短信发送被禁用");
            return;
        }
        Assert.notNull(userId,"userId is null");
        Assert.notNull(templateKey,"templateKey is null");
        sendSmsLocalService.sendSmsByUserId(userId,templateKey,params);
    }

    @Override
    public void sendSmsByMobile(String mobileNo, String templateKey, List<Object> params) {
        if (!isEnableSMS()) {
            log.info("短信发送被禁用");
            return;
        }
        Assert.notNull(mobileNo,"mobileNo is null");
        Assert.notNull(templateKey,"templateKey is null");
        sendSmsLocalService.sendSmsByMobile(mobileNo,templateKey,params);
    }

    @Override
    public void sendSmsByMobileWithTempId(String mobileNo, Long templateId, List<Object> params) {
        if (!isEnableSMS()) {
            log.info("短信发送被禁用");
            return;
        }
        Assert.notNull(mobileNo,"mobileNo is null");
        Assert.notNull(templateId,"templateId is null");
        sendSmsLocalService.sendSmsByMobileWithTempId(mobileNo,templateId,params);
    }

    @Override
    public void sendSmsByMobile(String mobileNo, String content) {
        if (!isEnableSMS()) {
            log.info("短信发送被禁用");
            return;
        }
        Assert.notNull(mobileNo,"mobileNo is null");
        Assert.notNull(content,"content is null");
        sendSmsLocalService.sendSmsByMobile(mobileNo,content);
    }
}
